package com.inspur_video.inspur_video.controller;

import com.inspur_video.inspur_video.bean.History;
import com.inspur_video.inspur_video.bean.tofront.HistoryInfo;
import com.inspur_video.inspur_video.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-07-25 17:24
 * @package com.inspur_video.inspur_video.controller
 * @description 历史记录
 */
@RestController
public class HistoryController {
    @Autowired
    HttpSession httpSession;
    @Autowired
    HistoryService historyService;

    /**
     * 获取观看历史记录
     *
     * @return
     */
    @RequestMapping("/history/{uid}")
    public List<HistoryInfo> getHistoryInfo(@PathVariable("uid") int id) {
        List<HistoryInfo> historyInfos = new LinkedList<>();
//        Object id = httpSession.getAttribute("user");
//        System.out.println(httpSession.getId());
        System.out.println("****" + id);
        List<History> list = historyService.findByUIdOrderByWatchTime(id);
        for (History history : list) {
            HistoryInfo historyInfo = new HistoryInfo();
            historyInfo.setDesc(history.getVDescribe());
            historyInfo.setTitle(history.getVTitle());
            historyInfo.setTime(history.getWatchTime());
            historyInfo.setVID(history.getVId());
            historyInfos.add(historyInfo);
        }
        return historyInfos;
    }
}
